import { getAction, deleteAction, postAction } from '@/api/manage'
import { serviceApi } from '@/api/common.js'
/**
 * 公共API接口
 */
export const api = {
  list: (roleId) => serviceApi.auth + `/users/app-roles/${roleId}`,
  userList: serviceApi.auth + '/users/select-app-role-user',
  listUserTenant: (tenantId, userId) => serviceApi.auth + `/tenants/${tenantId}/users/${userId}/list-user-tenant`,
  delete: (userId, roleId) => serviceApi.auth + `/users/${userId}/roles/${roleId}`,
  deleteBatch: (roleId) => serviceApi.auth + `/users/roles/${roleId}/delete-batch`
}

/**
* 获取用户角色列表
* @param {*} params
* @returns
*/
export const getUserRoleList = (roleId, params) => getAction(api.list(roleId), params)

/**
 * 添加用户项目
 * @param params
 * @returns {*}
 */
export const addUserRole = (params) => postAction(serviceApi.auth + '/users/tenants/add-user', params);

/**
 * 添加已有用户的角色关系
 * @param roleId
 * @param params
 * @returns {AxiosPromise}
 */
export const addExistUser = (roleId, params) => postAction(serviceApi.auth + `/users/roles/${roleId}/users`, params);

/**
 * 删除用户角色
 * @param params
 * @returns {AxiosPromise}
 */
export const deleteUserRole = (userId, roleId, params) => deleteAction(api.delete(userId, roleId), params);

/**
 * 批量删除用户角色
 * @param params
 * @returns {AxiosPromise}
 */
export const batchDeleteUserRole = (userId, roleId, params) => deleteAction(api.delete(userId, roleId), params);

/**
 * 获取应用角色用户添加列表
 * @param params
 * @returns {AxiosPromise}
 */
export const getAppRoleUserList = params => getAction(api.userList, params)
